/*
 * @Author: yangdingyuan yangdingyuan@bjjy.com
 * @Date: 2022-10-08 11:50:50
 * @LastEditors: yangdingyuan
 * @LastEditTime: 2022-10-08 13:52:51
 * @Description: axios封装
 */
import { message } from 'antd';
import axios from 'axios';

var handler;
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8';

const instance = axios.create({
  baseURL: import.meta.env.VITE_APP_AJAX_BASEURL || '/',
  timeout: 60 * 60 * 1000
});

instance.interceptors.request.use((req) => {
  handler = message.loading('正在处理中..', 0);
  return req;
});

instance.interceptors.response.use((res) => {
  setTimeout(handler, 0);
  if (res.status === 200) {
    return res.data;
  } else {
    message.error('系统在请求时发生错误');
    return {};
  }
});

export default instance;
